package com.zprmb.udzt;

import java.util.List;

import android.app.ActivityManager;
import android.app.ActivityManager.RunningTaskInfo;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.util.Log;

import com.umeng.analytics.MobclickAgent;
import com.zprmb.udzt.gesture.GestureVerifyActivity;
import com.zprmb.udzt.layout.AutoLayoutActivity;

public class QQActivity extends AutoLayoutActivity {
	private SharedPreferences sp;

	@Override
	protected void onCreate(Bundle arg0) {
		// TODO Auto-generated method stub
		super.onCreate(arg0);
		sp = getSharedPreferences("config", MODE_PRIVATE);
	}

	protected void onResume() {
		super.onResume();
		if (isTopActivity("com.zprmb.udzt")) {
			if (sp.getString("isTop", "").equals("1")) {
				if (sp.getInt("isShowGester", 0) == 1) {
					Editor editor = sp.edit();
					editor.putInt("isShowGester", 0);
					editor.putString("isTop", "2");
					editor.commit();
					return;
				}
				if (sp.getString("ss_password", "").equals("")) {
					Editor editor = sp.edit();
					editor.putString("isTop", "2");
					editor.commit();
				}
				// else {
				// if (sp.getBoolean("isTouth", false)) {
				// Editor editor = getSharedPreferences("config",
				// MODE_PRIVATE).edit();
				// editor.putString("token", "");
				//
				// editor.commit();
				// }
				else {
					Intent intent = new Intent(getApplicationContext(),
							GestureVerifyActivity.class);// GestureVerifyActivity
					startActivity(intent);
					// Toast.makeText(this, "回到前台", 0).show();
					Editor editor = getSharedPreferences("config", MODE_PRIVATE)
							.edit();
					editor.putString("isTop", "2");
					editor.commit();

				}
			}
		} else {

		}
		// TCAgent.onResume(this);
		MobclickAgent.onResume(this);
		Log.e("onresume",
				sp.getInt("isShowGester", 0) + "---"
						+ sp.getString("isTop", ""));
	}

	public boolean isTopActivity(String packageName) {
		ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
		List<RunningTaskInfo> tasksInfo = activityManager.getRunningTasks(1);
		if (tasksInfo.size() > 0) {
			// System.out.println("---------------包名-----------"+tasksInfo.get(0).topActivity.getPackageName());
			// 应用程序位于堆栈的顶层
			if (packageName.equals(tasksInfo.get(0).topActivity
					.getPackageName())) {
				return true;
			}
		}
		return false;
	}
}
